console.log('-----2工厂方法模式-------')

//命名空间 防止冲突
// export namespace FactoryFn{

export {}
  //2.1 工厂方法模式
  //咖啡的基类
  abstract class Coffe{
    public coffeName: string;
    constructor(name: string) {
      this.coffeName = name;
      this.getCoffe(this.coffeName);
      console.log('我是coffee的基类！！！');
    }
    getCoffe(name:string) {
      console.log(`制作的是${name}咖啡`);
    }
  };
  // 创建咖啡实例的类
  class AmriCoffe extends Coffe {
    constructor(name:string) {
      super(name);
      console.log('我是创建Amri咖啡实例的类');
    }
  }
  class LatteCoffe extends Coffe {
    constructor(name:string) {
      super(name);
      console.log('我是创建latte咖啡实例的类');
    }
  }
  class FlowerCoffe extends Coffe {
    constructor(name:string) {
      super(name);
      console.log('我是创建Flower咖啡实例的类');
    }
  };
  // 创建’创建咖啡实例类的工厂‘
  class AmriCoffeFactory extends AmriCoffe {
    constructor(name:string) {
      super(name);
      this.setCoffe(name);
    }
    setCoffe(coffe:string){
      new AmriCoffe(coffe);
    }
  }
  class LatteCoffeFactory extends  LatteCoffe {
    constructor(name:string) {
      super(name);
      this.setCoffe(name);
    }
    setCoffe(coffe:string){
      new LatteCoffe(coffe);
    }
  }
  class FlowerCoffeFactory extends FlowerCoffe {
    constructor(name:string) {
      super(name);
      this.setCoffe(name);
    }
    setCoffe(coffe:string){
      new FlowerCoffe(coffe);
    }
  };

  //工厂的基类
  abstract class Factory{
    constructor(name: string) {
      console.log('我是工厂的基类！！！')
    }
  };

  class  FactoryFn extends Factory {
    constructor(name:any) {
      super(name);
    };
    //静态方法
    static order(coffeName: string) {
      switch (coffeName) {
        case '美式咖啡':
          return new AmriCoffeFactory(coffeName);
          break;
        case '拿铁咖啡':
          return new LatteCoffeFactory(coffeName);
          break;
        case '花式咖啡':
          return new FlowerCoffeFactory(coffeName);
          break;
        default:
          return 'sorry!我们这里没有这种咖啡！'
      }
    }
  }
// let res2 = FactoryFn.order('美式咖啡');
// new FactoryFn('hello ');
// console.log(res2);


// 2.2 工厂方法模式测试用例：raect中的例子
function createElement(type:any, config:any) {
  return {type,config:config}
};

function createFactory(type: any) {
  const factory = createElement.bind(null, type);
  return factory
};
let factory1 = createFactory('h1');
let element = factory1({ id: '123456', calssName: 'title' });
console.log(element);





// }






